//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __VIDEO_H__
#define __VIDEO_H__

#include <driver.h>
#include "shadow.h"
#include "dispatcher.h"
#include "framebuffer.h"

class CVideo: public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */  Int64 offset,
        /* [in] */  Int32 numberOfBytesToRead,
        /* [out] */ MemoryBuf * pData,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */  Int64 offset,
        /* [in] */ const  MemoryBuf & ebbData,
        /* [out] */ Int32 * pNumberOfBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */  Handle32 constrolCode,
        /* [in] */ const  MemoryBuf & ebbInData,
        /* [out] */ MemoryBuf * pOutData,
        /* [out] */ IEvent * * ppCompletionEvent);

    void Dispose();

    void EventDispatchLoop();

private:
    ECode CreateContext();

public:
    CVideo(Int32 posX,
        Int32 posY,
        Int32 width,
        Int32 height,
        Int32 environmentId,
        Int32 colorFormat)
        : m_environmentId(environmentId),
        m_shadow(0, 0, width, height, environmentId),
        m_context(posX, posY, width, height, colorFormat),
        m_dispatcher(),
        m_pShadowManager(NULL)
    {
        m_shadow.Initialize();
    }

    virtual ~CVideo();
    ECode Initialize();

private:
    Int32           m_environmentId;

    CShadow         m_shadow;
    CFrameBuffer    m_context;
    CEventDispatcher m_dispatcher;

    CShadowManager * m_pShadowManager;

    ECode  m_ecode;
    PVoid  m_hDispatcherThread;
    PVoid  m_hSyncEvent;
};

#endif //__VIDEO_H__
